In computer science, programmers use metasyntactic variables to describe a placeholder name or an alias term commonly used to denote the subject matter under discussion or an arbitrary member of a class of things under discussion. The use of a metasyntactic variable is helpful in freeing a programmer from creating a logically named variable, which is often useful when creating or teaching examples of an algorithm. The word foo is the principal example.[1]
The term "metasyntactic variable" is primarily found in informal literature. It is sometimes also used as a synonym for metavariable.
Any symbol or word which does not violate the rules of the language can be used as a metasyntactic variable, but nonsense words are commonly used. The same concept is employed in other fields where it is expressed by terms such as schematic variable (see logical form).
By mathematical analogy: A metasyntactic variable is a word that is a variable for other words, just as in algebra letters are used as variables for numbers.[1]
Contents |
So metasyntactic variable denotes a word that "transcends grammar and can assume a value" or one that is "more comprehensive than suggested by its grammatical arrangement and is likely to vary". It may also denote a word that provides information about the grammatical arrangement of words by being able to assume a value that is expected to vary.
A "standard list of metasyntactic variables used in syntax examples" often used in the United States is: foo, bar, baz, qux, quux, corge, grault, garply, waldo, fred, plugh, xyzzy, thud.[1] The word foo occurs in over 330 RFCs and bar occurs in over 290.[2] Wibble, wobble, wubble, Fred and flob are often used in the UK.[3]
In standard, non-computerese English, the usual metasyntactic variables are: whatever, whoever, whenever, et cetera.
In Japanese, the words hoge and page are commonly used, with other common words and variants being piyo, fuga, hogera, and hogehoge.[4] Note that -ra is a pluralizing ending in Japanese, and reduplication is also used for pluralizing. The origin of hoge as a metasyntactic variable is not known, but it is believed to date to the early 1980s.[4]
In Hebrew, the words chupchick and stam are commonly used.
In Italian, the word pippo is commonly used. Strangely enough, besides being an abbreviation of the first name Filippo (Philip), pippo is the Italian name of the Disney character Goofy, but it is probably used just because of its sound which is quite strange.
In Portuguese, the words fulano, cicrano and beltrano are commonly used. These words have the constraint that they can only be used to refer to people.
In Spanish, the words fulano, sutano and mengano are commonly used, often followed by de tal mocking a lastname in spanish form (i.e. Fulano de Tal). These words have the constraint that they can only be used to refer to people, as in the case with portuguese. Also, when referring to an example of some person performing a certain action, Perico de los Palotes can also be used as a placeholder for a real name. In place of people or objects (including numbers, etc.) the usual X, Y, Z are used (i.e. Person X, Quantity X).
In the following example of the C programming language the function name foo and the variable name bar are both metasyntactic variables. Lines beginning with // are comments.
// The function named foo int foo(void) { // Declare the variable bar and set the value to 1 int bar = 1; return bar; }
Spam, ham, and eggs are the principal metasyntactic variables used in the Python programming language.[5] This is a reference to the famous comedy sketch, Spam, by Monty Python, the eponym of the language.[6] In the following example spam, ham, and eggs are metasyntactic variables and lines beginning with # are comments.
# Define a function named spam def spam(): # define the variable ham ham = "Hello World!" #define the variable eggs eggs = 1 return
In the following example the baz, foo, and bar are metasyntactic variables and lines beginning with # are comments.
# Declare the variable foo and set equal to 1 foo = 1 # Declare the variable bar and set equal to 2 bar = 2 # Declare the method (function) named baz, which prints the text 'Hello world' def baz puts 'Hello world' end